package fr.mywiki.model.ejbAdapter.entity;

import javax.ejb.CreateException;
import javax.ejb.EntityBean;

import fr.mywiki.business.account.AccountLite;
import fr.mywiki.business.profil.ProfileManager;


/**
 * @ejb.bean name="Account"
 *		local-jndi-name="ejb/MyWiki/Account"
 *		view-type="local"
 *		cmp-version="2.x"
 *		primkey-field="id"
 *		schema="Account"
 *
 * @ejb.persistence table-name="account"
 * 
 * @ejb.finder view-type="local"
 *		signature="java.util.Collection findAll()"
 *		unchecked="true"
 *		query="SELECT OBJECT(e) FROM Account e"
 *		result-type-mapping="Local"
 * @ejb.finder view-type="local"
 * 		signature="java.util.Collection findByLogin(java.lang.String login)"
 * 		unchecked="true"
 *		query="SELECT OBJECT(e) FROM Account e WHERE e.login=?1"
 *		result-type-mapping="Local"
 * 
 * @author tlombard
 */
public abstract class AccountBean extends EntityAdapter implements EntityBean{
	/**
	 * @ejb.create-method
	 */
	public Long ejbCreate(Long id) throws CreateException {
		setId(id);
		return id;
	}
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id"
	 */
	public abstract Long getId();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id"
	 */
	public abstract void setId(Long id);
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="login"
	 */
	public abstract String getLogin();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="login"
	 */
	public abstract void setLogin(String id);
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="password"
	 */
	public abstract String getPassword();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id"
	 */
	public abstract void setPassword(String id);
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="profileId"
	 */
	public abstract Long getProfileId();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="profileId"
	 */
	public abstract void setProfileId(Long id);
	
	/**
	 * @ejb.interface-method view-type="local"
	 *
	 * @ejb.relation name="Account-to-Structure"
	 *		role-name="Account-has-one-structure"
	 *		target-role-name="Structure-has-many-accounts"
	 *
	 * @jboss.relation fk-column="structureId"
	 *		related-pk-field="id"
	 */
	public abstract StructureLocal getStructure();
	
	/**
	 * @ejb.interface-method
	 */
	public abstract void setStructure(StructureLocal structure);
	
	/**
	 * @ejb.interface-method view-type="local"
	 */
	public AccountLite getAccountLite() {
		AccountLite account = new AccountLite();

		account.setId(getId());
		account.setLogin(getLogin());
		account.setPassword(getPassword());
		if (getProfileId() != null)
			account.setProfile(ProfileManager.getInstance().getProfile(
					getProfileId()));
		
		return account;
	}
}
